package com.fourhats.services.impl;

import java.util.ArrayList;
import java.util.List;

import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;

import com.fourhats.dao.ItemDAO;
import com.fourhats.model.Item;
import com.fourhats.services.ItemService;
import com.fourhats.services.dto.ItemDto;

public class ItemServiceImpl implements ItemService {

	@Autowired
	private Mapper mapper;
	
	@Autowired
	private ItemDAO itemDAO;
	
	@Override
	public List<ItemDto> getItemsByKeyword(String keyWord) {
		List<Item> items = itemDAO.getItemsByKeyword(keyWord);
		List<ItemDto> dtos = new ArrayList<ItemDto>();
		for(Item i : items) {
			dtos.add(mapper.map(i, ItemDto.class));
		}
		
		return dtos;
	}

	@Override
	public List<String> getItemsNameByKeyword(String keyWord) {
		List<Item> items = itemDAO.getItemsByKeyword(keyWord);
		List<String> names = new ArrayList<String>();
		for(Item i : items) {
			names.add(i.getName());
		}
		
		return names;
	}
}
